<?php
/* SVN FILE: $Id: view.php 221 2009-09-16 19:05:39Z supersmashbrothers $ */
/**
* ibMarket 2
* IP.Board 3.0
* Items List page
*
* @author $Author: supersmashbrothers $
* @copyright $Copyright$
* @version $Revision: 221 $
* @lastrevision $Date: 2009-09-16 19:05:39 +0000 (Wed, 16 Sep 2009) $
* @modifiedby $LastChangedBy: supersmashbrothers $
* @lastmodified $LastChangedDate: 2009-09-16 19:05:39 +0000 (Wed, 16 Sep 2009) $
* @filesource $URL: http://ipb-ibmarket.googlecode.com/svn/ibmarket2/trunk/admin/applications_addon/other/ibmarket/modules_admin/items/view.php $
*/


if ( ! defined( 'IN_ACP' ) )
{
	print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded 'admin.php'.";
	exit();
}

class admin_ibmarket_items_view extends ipsCommand
{
	/**
	 * Skin object
	 *
	 * @access	private
	 * @var		object			Skin templates
	 */
	private $html;
	
	/**
	 * Main class entry point
	 *
	 * @access	public
	 * @param	object		ipsRegistry reference
	 * @return	void		[Outputs to screen]
	 */
	public function doExecute( ipsRegistry $registry )
	{
		$this->registry->getClass('class_permissions')->checkPermissionAutoMsg( 'item_edit' );
		
		$this->html = $this->registry->output->loadTemplate('cp_skin_items');
		
		$this->registry->getClass('class_localization')->loadLanguageFile( array( 'admin_market', 'admin_items' ) );
		
		$items = array();
		if(is_array($this->caches['market_category'][$this->request['category']]))
		{
			$categories = array($this->request['category']);
			if($this->request['showAll'])
			{
				for($i = 0; $i < count($categories); $i++)
				{
					if(!is_null(marketRegistry::getCategoryTree($categories[$i])))
					{
						foreach(marketRegistry::getCategoryTree($categories[$i]) as $_category)
						{
							$categories[] = $_category['cat_id'];
						}
					}
				}
			}
			foreach($categories as $category)
			{
				if(!is_null(marketRegistry::getItemsByCategory($category)))
				{
					foreach(marketRegistry::getItemsByCategory($category) as $item)
					{
						$items[] = $item;
					}
				}
			}
		}
		else
		{
			if(!is_array($this->caches['market_items']) || count($this->caches['market_items']) == 0)
			{
				$this->registry->output->silentRedirect($this->settings['base_url']."module=items&amp;section=add");
			}
			$items = $this->caches['market_items'];
		}
		
		$this->registry->output->html = $this->html->listItems( $items );
		
		$this->registry->getClass('output')->html_main .= $this->registry->getClass('output')->global_template->global_frame_wrapper();
		$this->registry->getClass('output')->sendOutput();
	}
}